

import javax.swing.*;
import java.awt.*;

public class WindowOne extends JFrame {
    JTextField textField;
    JPasswordField passwordField;
    JButton button;
    WindowOneListener windowOneListener;

    WindowOne() {
        init();
        setTitle("实验报告小助手");
        setSize(350, 500);
        setLocationRelativeTo(null);
        setVisible(true);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    void init() {
        Box boxOne, boxTwo, boxThree, boxFour, boxFive, boxAll;
        JLabel jLabel1;
        JPanel jPanel;

        jLabel1 = new JLabel("实验报告小助手 —— 教师登录");
        jLabel1.setFont(new Font("仿宋", Font.BOLD, 18));
        textField = new JTextField();
        textField.setPreferredSize(new Dimension(220, 22));//文本框长高
        passwordField = new JPasswordField();
        passwordField.setPreferredSize(new Dimension(220, 22));

        boxAll = Box.createVerticalBox();
        boxOne = Box.createHorizontalBox();
        boxTwo = Box.createHorizontalBox();
        boxThree = Box.createHorizontalBox();
        boxFour = Box.createHorizontalBox();
        boxFive = Box.createHorizontalBox();

        boxOne.add(jLabel1);
        boxTwo.add(new JLabel("用户名："));

        boxTwo.add(textField);
        boxThree.add(new JLabel("密码    ："));
        boxThree.add(passwordField);

        button = new JButton("登录");
        button.setBackground(Color.white);//按钮样式设置
        button.setFocusPainted(false);
        boxFour.add(button);

        boxAll.add(Box.createVerticalStrut(30));//间距
        boxAll.add(boxOne);
        boxAll.add(Box.createVerticalStrut(30));
        boxAll.add(boxTwo);
        boxAll.add(Box.createVerticalStrut(30));
        boxAll.add(boxThree);
        boxAll.add(Box.createVerticalStrut(30));
        boxAll.add(boxFour);

        jPanel = new JPanel();
        jPanel.add(boxAll);

        windowOneListener = new WindowOneListener();
        windowOneListener.setWindowOne(this);
        button.addActionListener(windowOneListener);


        this.setLayout(new BorderLayout());
        this.add(jPanel, BorderLayout.NORTH);
    }
}
